/**
 * 
 */
package com.gr.staffpm.widget.calendar.model;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxFallbackLink;

import com.gr.staffpm.widget.calendar.Calendar;


/**
 * @author Graham Rhodes 8 Jan 2011 22:28:08
 */
public class CalendarIterButton extends IndicatingAjaxFallbackLink<Void> {

    private static final long serialVersionUID = 1L;
    private final Calendar cal;
    private int amountToIterateBy = 0;

    public CalendarIterButton(String id, Calendar cal, int amountToIterateBy) {
        super(id);
        this.cal = cal;
        this.amountToIterateBy = amountToIterateBy;
    }

    @Override
    public void onClick(AjaxRequestTarget target) {
        if (cal.getView().equals(Views.DAY))
            cal.getCal().add(java.util.Calendar.DAY_OF_MONTH, amountToIterateBy);
        else if (cal.getView().equals(Views.WEEK))
            cal.getCal().add(java.util.Calendar.WEEK_OF_MONTH, amountToIterateBy);
        else if (cal.getView().equals(Views.MONTH))
            cal.getCal().add(java.util.Calendar.MONTH, amountToIterateBy);

        cal.getMonthName().setDefaultModel(new MonthLabelModel(cal.getCal()));
        cal.updateView();
        target.addComponent(cal.getEventContainer());
        target.addComponent(cal.getMonthName());
    }
}
